# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution(object):
    def rightSideView(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        if not root: return []
        history = []
        queue = [root]
        while queue:
            newQueue = []
            for root in queue:
                if root.right: newQueue.append(root.right)
                if root.left: newQueue.append(root.left)
            history.append(queue[0].val)
            queue = newQueue
        return history

root = TreeNode(1)
print(Solution().rightSideView(root))